package com.qidi.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.codec.ServerSentEvent;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.util.function.Tuples;

import java.time.Duration;
import java.util.concurrent.ThreadLocalRandom;

/**
 * 包    名 ：com.qidi.platform.ui
 * 文 件 名 : RestTestController
 * 描    述 : TODO
 * 作    者 ：zhouchao超哥
 * 创建时间 ：2018/6/13 11:28
 * 版    本 ：1.0
 */
@RestController
@RequestMapping
public class RestTestController {




    @GetMapping("customer/{id}")
    public Mono<String> findByIdWithAccounts(@PathVariable("id") String id){

        Mono<String> mono = Mono.create(s->{s.success("hello1");});

        return  mono;

    }

    @GetMapping("/randomNumbers")
    public Flux<ServerSentEvent<Integer>> randomNumbers() {
        return Flux.interval(Duration.ofSeconds(1))
                .map(seq -> Tuples.of(seq, ThreadLocalRandom.current().nextInt()))
                .map(data -> ServerSentEvent.<Integer>builder()
                        .comment("订单事件推送")
                        .event("random")
                        .id(Long.toString(data.getT1()))
                        .data(data.getT2())
                        .build());
    }

}
